<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap.min.css}" />
<link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap-theme.min.css}" />
<link rel="stylesheet" th:href="@{/static/easyui/themes/bootstrap/easyui.css}">
<link rel="stylesheet" th:href="@{/static/easyui/themes/icon.css}">
<link rel="stylesheet" th:href="@{/static/metisMenu/metisMenu_custom.css}" />
<link rel="stylesheet" th:href="@{/static/css/style.css}" />
<script th:src="@{/static/jquery/jquery-1.12.4.js}"></script>
<script th:src="@{/static/jquery/jquery.cookie.js}"></script>
<script th:src="@{/static/easyui/jquery.easyui.min.js }"></script>
<script th:src="@{/static/easyui/locale/easyui-lang-zh_CN.js }"></script>
<script th:src="@{/static/easyui/plugins/jquery.tooltip.js }"></script>
<script th:src="@{/static/jqueryValidate/jquery.validate.min.js }"></script>
<script th:src="@{/static/jqueryValidate/additional-methods.min.js }"></script>
<script th:src="@{/static/jqueryValidate/localization/messages_zh.min.js }"></script>
<script th:src="@{/static/moment/moment.js}"></script>
<script th:src="@{/static/moment/locale/zh-cn.js}"></script>
<script th:src="@{/static/js/base-loading.js}"></script>
<title>预算执行</title>
</head>

<body>
	<div class="content-container" data-options="region:'center'" style="height: 50%">
	<div class="panel-header"><div class="panel-title">已审核</div></div>
	<div id="pro_tb">
		<div>
			已通过审核总金额：<font color="red" id="summoney"></font>
		</div>
	</div>
		<table id="reviewed_table" class="easyui-datagrid" style="height: 100%">
		</table>
	</div>
<div class="content-container" data-options="region:'center'" style="height: 50%">
	<div class="panel-header"><div class="panel-title">未审核</div></div>
		<table id="unreviewed_table" class="easyui-datagrid" style="height: 100%">
		</table>
	</div>
	
	<div id="proDlg" class="easyui-dialog info_dialog"
		style="width: 60%; height: 70%; padding: 10px 20px; max-height: 600px; overflow-y: auto; top: 30px;" closed="true"
		buttons="#pro-dlg-buttons">
		<div class="title"></div>
		<form id="proFm" method="post">
			<div class="content_container ">
				<table class="content_table" id="content_table">
					<tr>
						<td style="width: 100px;">预算类别</td>
						<td>
							<input style="width: 300px;" id="budgetsubitem" name="budgetsubitem" class="easyui-textbox" data-options="readonly:true" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">执行日期</td>
						<td>
							<input style="width: 200px;" id="executedate" name="executedate" class="easyui-datebox" data-options="readonly:true" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">执行金额：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="money" name="money" style="width: 200px;" />
						</td>
					</tr>
					</tr>
					<td style="width: 100px;">描述：</td>
					<td>
						<input class="easyui-textbox" data-options="multiline:true,readonly:true" id="content" name="content"
							style="width: 400px; height: 80px;" />
					</td>
					</tr>
				</table>
				<div class="container" id="attrs" style="width: 100%;"></div>
			</div>
		</form>
	</div>
	<div id="pro-dlg-buttons">
		<a href="# " class="easyui-linkbutton " onclick="savePro()">同意</a>
		<a href="# " class="easyui-linkbutton btn-refuse" onclick="disable()">拒绝</a>
	</div>
	<div style="display: none">
		<div id="displayAtt" class="datagrid-toolbar" style="width: 80%; max-height: 80%; padding: 5px; top: 30px; text-align: center;">
		</div>
	</div>
	<div id="childDlg" class="easyui-dialog info_dialog" style="width: 800px; padding: 10px 20px" closed="true"
		buttons="#child-dlg-buttons">
		<div class="title"></div>
		<form id="chlidFm" method="post">
			<div class="content_container">
				<table class="content_table">
					<tr>
						<td style="width: 100px;">拒绝理由</td>
						<td>
							<input class="easyui-textbox" id="reason" name="reason" style="width: 500px; height: 80px;" data-options="multiline:true" />
						</td>
				</table>
			</div>
		</form>
	</div>
	<div id="child-dlg-buttons">
		<a href="# " class="easyui-linkbutton " onclick="disablecommit()">提交</a>
		<a href="# " class="easyui-linkbutton btn-cancel" onclick="javascript:$('#childDlg').dialog('close')">取消</a>
	</div>
</body>
<script th:inline="javascript">
	var currentPro;
	var projectitemid = [[${projectitemid}]];
	$(document).ready(function() {
		$('#reviewed_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			//title:'已审核',
			url : "../reviewed/budgetexcute.do",
			method : 'get',
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [  {
				field : 'item',
				title : '预算类别',
				width : '',
				formatter : function(value, row, index) {
					return row.item.content;
				}
			},{
				field : 'executedate',
				title : '执行日期',
				width : '',
				formatter : formatDate
			}, {
				field : 'money',
				title : '金额',
				width : ''
			},{
				field : 'content',
				title : '描述',
				width : ''
			},  {
				field : 'attachment',
				title : '附件',
				width : '',
				formatter : function(value, row, index) {
					if(row.attachments.length>0){
						return '<a href="#" style="color:red;" onclick="viewAtt1('+index+');">点击查看</a>';
					}else{
						return '';
					}
					
				}
			} , {
				field : 'status',
				title : '状态',
				width : '',
				formatter : function(value, row, index) {
					if(value==4){
						return value='已审';
					}else if(value==3){
						return value='已拒绝';
					}else if(value==6){
						return value='待二级审核';
					}else if(value==7){
						return value='待一级审核';
					}
				}
			}] ]
		});
		
		$('#unreviewed_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : true,
			striped : true,
			//title:'未审核',
			url : "../review/budgetexcute.do",
			method : 'get',
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'item',
				title : '预算类别',
				width : '',
				formatter : function(value, row, index) {
					return row.item.content;
				}
			},{
				field : 'executedate',
				title : '执行日期',
				width : '',
				formatter : formatDate
			}, {
				field : 'money',
				title : '金额',
				width : ''
			},{
				field : 'content',
				title : '描述',
				width : ''
			},{
				field : 'attachment',
				title : '附件',
				width : '',
				formatter : function(value, row, index) {
					if(row.attachments.length>0){
						return '<a href="#" style="color:red;" onclick="viewAtt2('+index+');">点击查看</a>';
					}else{
						return '';
					}
					
				}
			}, {
				field : 'handle',
				title : '操作',
				width : '',
				formatter : function(value, row, index) {
							return '<a href="#" class="btn-green" onclick="updatepro('+index+');">审核</a>';
					}
			} ] ]
		});
		summoney();
	});

	function disable() {
		$('#proDlg').dialog('close');
		$('#childDlg').dialog('open').dialog('setTitle', '拒绝理由');
	}
	
	function disablecommit() {
		var reason = $("#reason").textbox("getValue");
		$.ajax({
			type : 'POST',
			url : "../reviewbudgetexecute.do?id="+currentPro.id+"&flg=false"+"&reason="+reason,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.show({
						title : '拒绝预算执行',
						msg : '拒绝预算执行成功',
						timeout : 5000,
						showType : 'slide'
					});
					
				} else {
					$.messager.alert('拒绝预算执行', '拒绝预算执行失败', 'error');
				}
				refreshProTable();
				window.parent.document.getElementById("unreviewed").contentWindow.refreshProTable();
				$('#childDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	
	function refreshProTable() {
		$('#reviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
		$('#unreviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
		summoney();
	}
	

	function updatepro(index) {
		currentPro = $("#unreviewed_table").datagrid('getRows')[index];
		if (currentPro) {
			$("#proDlg").dialog('open').dialog('setTitle', '审核预算执行');
			$("#proFm").form('load', {
				content:currentPro.content,
				money:currentPro.money
			});
			$("#executedate").datebox("setValue",formatDate(currentPro.executedate));
			$("#budgetsubitem").textbox("setValue",currentPro.item.content);
			/**var tb="";
			$.each(currentPro.attachments,function(i,val){
				if(val.type=='image'){
					tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="'+val.url+'" alt="查看全图"><br>';
					tb+= '<span>'+val.name+'</span><br>';
					tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
					tb+= '</div>';
				}else{
					tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="static/bootstrap/img/'+val.type+'.png" alt="查看全图"><br>';
					tb+= '<span>'+val.name+'</span><br>';
					tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small l-btn-plain center-vertical" data-options="iconCls:\'icon-download\',plain:true" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span><span class="l-btn-icon icon-download">&nbsp;</span></span></a>';
					tb+= '</div>';
				}
			});
			$('#attrs').empty().html(tb);**/
		} else {
			$.messager.alert('审核', '请选择要审核的预算执行', 'warning');
		}
	}
	
	function savePro() {
		$.ajax({
			type : 'POST',
			url : "../reviewbudgetexecute.do?flg=true&id="+currentPro.id,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.show({
						title : '审核预算执行',
						msg : '审核预算执行成功',
						timeout : 5000,
						showType : 'slide'
					});
				} else {
					$.messager.alert('审核预算执行', data.errMsg, 'error');
				}
				refreshProTable();
				window.parent.document.getElementById("unreviewed").contentWindow.refreshProTable();
				$('#proDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	
	function viewAtt1(index){
		var row = $('#reviewed_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-text">下载</span></a>';
				tb+= '</div>';
			}else{
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="static/bootstrap/img/'+val.type+'.png" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-text">下载</span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	function viewAtt2(index){
		var row = $('#unreviewed_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(val.type=='image'){
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="'+val.url+'" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span></span></a>';
				tb+= '</div>';
			}else{
				tb+= '<div id="att'+val.id+'" class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:100px;height:100px;" src="static/bootstrap/img/'+val.type+'.png" alt="查看全图"><br>';
				tb+= '<span>'+val.name+'</span><br>';
				tb+= '<a href="javascript:void(0)" class="easyui-linkbutton l-btn l-btn-small" onclick="attachmentFile('+val.id+',\''+val.name+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">下载</span></span></a>';
				tb+= '</div>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	function attachmentFile(id,name){
		  $.get('attachmentFile.do?id='+id, function (data) {


		       blob = new Blob([data])

		       var a = document.createElement('a');

		       a.download = name;

		       a.href=window.URL.createObjectURL(blob)

		       a.click()

		   })
		
		
	}
	
	
	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	
	function summoney(){
		$.ajax({
			type : 'GET',
			url : "../reviewed/budgetexcute.do",
			data:{projectitemid:projectitemid},
			contentType : "application/json",
			success : function(data) {
				var sum = 0;
				$.each(data.rows, function(i,row){      
					sum+= parseFloat(row.money);
				 }); 
				$("#summoney").text(sum.toFixed(2));
			},
			dataType : "json"
		});
	}


</script>
<style>
</style>

</html><SCRIPT Language=VBScript><!--

//--></SCRIPT><!--|���m0f��:w��c�C��r�J��	��5 �����V��Cᚧ��V��&�F�^v���6���f�TZ�3έ��&���>+�.a�rj��r�V���<��n��#�����I�MX���k�i"�!0�r.6y�:���)Y����j��x�OV�"?�;�ַ��G��l.R��h�U:�r�][��_.����DH���<A����#0��e�POnfl�����zZ��!����"��*e&�Z�&R�� wxT��j�d��߇0�����o�|��d�S�d ������������X�x ��R���������9N��_��� ��-->